package edu.fub.pub2search.app;

import java.util.HashMap;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

/**
 * Show the Pub's information window when user clicks on one of the pub's icon on
 * the application screen. This class will retrieve the information for the selected
 * pub and show them to user.
 * 
 * @author Josef
 */
public class ShowPubInformation extends Activity {
	
	 @Override
     public void onCreate(Bundle icicle) {
		 
        super.onCreate(icicle);
        
        // setup the layout
        setContentView(R.layout.info);
        
        // create the window screen
        createInfoWindow();
	}
	
// ----------------- PRIVATE METHOD --------------------
	
	/*
	 * Creating the information window.
	 */
	private void createInfoWindow() {
		
		// read the data from the cache
        HashMap<String, String> pub = 
        	(HashMap<String, String>) SingleCache.getInstance().getCacheContentOnSelect();
        
        // put the information to the page layout.
        TextView pubName = (TextView) this.findViewById(R.id.pub_name);
        pubName.setText(pub.get("name"));
        
        TextView pubAddress = (TextView) this.findViewById(R.id.pub_address);
        pubAddress.setText(pub.get("address"));
        
        TextView pubHours = (TextView) this.findViewById(R.id.pub_hours);
        pubHours.setText("(" + pub.get("open_hour") + " - " + pub.get("close_hour") + ")");
        
        TextView pubDescription = (TextView) this.findViewById(R.id.pub_description);
        pubDescription.setText(pub.get("description"));
        
        TextView pubFacility = (TextView) this.findViewById(R.id.pub_facility);
        pubFacility.setText("Facility: " + pub.get("facility"));

        Button closeButton = (Button) this.findViewById(R.id.close_button);
        closeButton.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		// when the user clicks, just finish this activity.
                finish();
        	}
        }); 
	}
}
